#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<stack>
using namespace std;
string word[100];
int dp[100],sum[100],from[100],inf=111111;
int cost(int x,int y,int m)
{
    return m-(sum[y]-sum[x-1]+y-x);
}
int main()
{
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>word[i],sum[i]=sum[i-1]+word[i].length();
    memset(dp,0x3f,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i-1;j++)
        {
            int c=cost(j+1,i,m);
            if(c<0) continue;
            c=pow(c,3);
            if(dp[i]>dp[j]+c)
            {
                dp[i]=dp[j]+c;
                from[i]=j;
            }
        }
    }
    cout<<dp[n]<<endl;
    stack<int> put;
    for(int i=n;i;i=from[i])
    {
        put.push(i);
    }
    int cnt=1;
    while(!put.empty())
    {
        for(int i=cnt;i<=put.top();i++)
        cout<<word[i]<<" ";
        cout<<endl;
        cnt=put.top()+1;
        put.pop();
    }
}

// 39 15
// If you were a teardrop In my eye
// For fear of losing you I would never cry 
// And if the golden sun Should cease to shine its light
// Just one smile from you Would make my whole world bright

// 10 8
// abc def gh polq cs opaqe klfgh t asd th 